<?php

namespace common\ui\backend\widgets;


use common\models\db\AdminRole;
use yii\base\Widget;

/**
 *
 */
class OperationWidget extends Widget
{
    public $content = '';
    public $id = '';

    public function run()
    {
        $adminUser = \Yii::$app->user->getIdentity();
        if (!$adminUser) {
            return '';
        }
        $disabled = true;
        if ($adminUser->user_name == 'admin' || $adminUser->user_name == 'test') {
            $disabled = false;
        }
        $adminRole = AdminRole::findOne($adminUser->role_id);
        if ($adminRole) {
            $menus = json_decode($adminRole->menus, true);
            if (in_array($this->id, $menus)) {
                $disabled = false;
            }
        }
        if($disabled){
            return '';
        }
        echo $this->render('operation', [
            'content' => $this->content
        ]);
    }
}